package controllers

import (
	"github.com/gin-gonic/gin"
	"rongyy/src/middlewares"
	"rongyy/src/models"
	"rongyy/src/server"
	"rongyy/src/service"
)

type WxNoticeController struct {
	*service.WxNoticeService
}

func NewWxNoticeController() *WxNoticeController {
	return &WxNoticeController{}
}

func (rc *WxNoticeController) send(ctx *gin.Context) server.IModel {
	req := &models.ReqNoticeParams{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		middlewares.Logger.Println("ShouldBindJSON failed in findPatientCard ", err)
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}
	err := rc.SendNotice1(req)
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true, Msg: "发送成功"}
}

func (rc *WxNoticeController) suspend(ctx *gin.Context) server.IModel {
	req := &models.ReqNoticeParams{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		middlewares.Logger.Println("ShouldBindJSON failed in suspend ", err)
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}
	err := rc.Suspend(req)
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true, Msg: "发送成功"}
}
func (rc *WxNoticeController) innerSend(ctx *gin.Context) server.IModel {
	req := &models.ReqNoticeParams{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		middlewares.Logger.Println("ShouldBindJSON failed in findPatientCard ", err)
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}
	err := rc.SendNotice1(req)
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true, Msg: "发送成功"}
}
func (rc *WxNoticeController) caseNotice(ctx *gin.Context) server.IModel {
	req := &models.ReqNoticeParams{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		middlewares.Logger.Println("ShouldBindJSON failed in findPatientCard ", err)
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}
	err := rc.CaseNotice(req)
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true, Msg: "发送成功"}
}

func (rc *WxNoticeController) opUnpaid(ctx *gin.Context) server.IModel {
	req := &models.ReqNoticeParams{}
	//req := &models.ReqNoticeParams{}
	if err := ctx.ShouldBindJSON(req); err != nil {
		middlewares.Logger.Println("ShouldBindJSON failed in findPatientCard ", err)
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}
	//_, err := helper.PostJson("https://cd10yy.assetbigdata.com/msg/op-unpaid", req)
	err := rc.SendNoticeOpUnpaid(req)
	if err != nil {
		return &models.DataModel{IsSuccess: false, Msg: err.Error()}
	}

	return &models.DataModel{IsSuccess: true, Msg: "发送成功"}
}

func (u *WxNoticeController) RouterHandler(server *server.Server) {
	server.Handle("POST", "/send", u.send)
	server.Handle("POST", "/suspend", u.suspend)
	server.Handle("POST", "/case-notice", u.caseNotice)
	server.Handle("POST", "/op-unpaid", u.opUnpaid)
}
